package com.zenni.core;

import com.zenni.utils.DriverUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

/**
 * Created by douglasj on 3/1/16.
 */
public class FramelistFunction {
    private WebDriver driver;
    private DriverUtils driverUtils = new DriverUtils();
    public FramelistFunction(WebDriver driver) throws Exception{
        this.driver = driver;
    }
    public String getCurrentFrameCatorgray() throws Exception{
        String categoryheader = driver.findElement(By.xpath(FrameListVariables.categoryheader_xpath)).getText();
        return categoryheader;
    }
    public String getCurrentFilter() throws Exception{
        String current_filter = driver.findElement(By.xpath(FrameListVariables.filter_text_xpath)).getText();
        return current_filter;
    }
    public void selectAcategory(String category) throws Exception{
        Select filter = new Select(driver.findElement(By.xpath(FrameListVariables.fiter_id)));
        filter.selectByVisibleText(category);
    }
    public void orderAFrame(int index) throws Exception{
        if(driver.findElement(By.xpath(HomePageVariables.hamburger_menu_button_xpath)).isDisplayed()){
            driverUtils.waitTillElementExistsByXpath(driver,FrameListVariables.order_button_xpath_mobile,3000);
            driver.findElement(By.xpath("//ul[@class = 'categoryList']/li["+index+"]/div/div/p[@class = 'btnBox']/a[3]")).click();
        }else {
            JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("document.getElementsByClassName('thumbOver')["+index+"].style.display='block'");
            //driverUtils.waitTillElementExistsByXpath(driver,FrameListVariables.order_button_xpath,3000);
            driver.findElements(By.xpath(FrameListVariables.order_button_xpath)).get(index).click();
        }
        Thread thread = new Thread();
        thread.sleep(3000);
    }

}
